<template>
  <div class="app-container universal-from">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="100px"
      class="el-form"
    >
      <!-- type="textarea" -->
      <div class="disp-from-flxe">
        <el-form-item label="公司名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="code">
          <el-input v-model="form.code" placeholder="请输入内容"></el-input>
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="所属类目" prop="cateArr">
          <el-select
        @change="chaSel"
            v-model="form.cateArr"
            multiple
            filterable
            allow-create
            default-first-option
            placeholder="请选择"
          >
            <el-option
              v-for="item in cateArr"
              :key="item.id+''"
              :label="item.name"
              :value="item.id+''"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="公司性质" prop="nature">
          <el-input v-model="form.nature" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="纳税人资质" prop="aptitude">
          <el-input v-model="form.aptitude" placeholder="请输入内容"></el-input>
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="联系人姓名" prop="leader">
          <el-input v-model="form.leader" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="联系人电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入内容"></el-input>
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="邮箱">
          <el-input v-model="form.email" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="经营场地地址">
          <el-input v-model="form.address" placeholder="请输入内容"></el-input>
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="面积">
          <el-input v-model="form.area" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="产权">
          <el-input v-model="form.equity" placeholder="请输入内容"></el-input>
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="是否具备运输系统" prop="isCar">
          <el-radio-group v-model="form.isCar">
            <el-radio-button label="1">是</el-radio-button>
            <el-radio-button label="0">否</el-radio-button>
          </el-radio-group>
          <!-- <el-input v-model="form.isCar" placeholder="请输入内容"></el-input> -->
        </el-form-item>

        <el-form-item label="保额" prop="sumInsured">
          <el-input
            v-model="form.sumInsured"
            placeholder="请输入内容"
          ></el-input>
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="营业执照照片" prop="license">
          <ImageUpload
            :limit="1"
            :isShowTip="false"
            :fileSize="99"
            v-model="form.license"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="食品经营许可证" prop="food">
          <ImageUpload
            :limit="1"
            :isShowTip="false"
            :fileSize="99"
            v-model="form.food"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="法人身份证正面" prop="idCardTop">
          <ImageUpload
            :limit="1"
            :isShowTip="false"
            :fileSize="99"
            v-model="form.idCardTop"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="法人身份证反面" prop="idCardBack">
          <ImageUpload
            :limit="1"
            :isShowTip="false"
            :fileSize="99"
            v-model="form.idCardBack"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="食品检测员（高级）" prop="foodInspector">
          <ImageUpload
            :limit="1"
            :isShowTip="false"
            :fileSize="99"
            v-model="form.foodInspector"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="经营人员健康证" prop="health">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.health"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="业绩证明" prop="performance">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.performance"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="产权证明" prop="equityCert">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.equityCert"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="车辆" prop="car">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.car"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="常温车数量" prop="carNum1">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.carNum1"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="冷藏车数量" prop="carNum2">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.carNum2"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="食品保险" prop="foodInsurance">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.foodInsurance"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>

      <div class="disp-from-flxe"></div>

      <div class="disp-from-flxe">
        <el-form-item label="纳税证明.社保（6月）" prop="socialSecurity">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.socialSecurity"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item
          label="国家企业信用信息公示系统查询结果截图"
          prop="iso9001"
        >
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.iso9001"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>
      <div class="disp-from-flxe">
        <el-form-item label="其他资质">
          <ImageUpload
            :isShowTip="false"
            :fileSize="99"
            v-model="form.other"
            placeholder="请输入内容"
          />
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </div>
</template>
  
  <script>
import { getFormatCateData } from "@/api/system/cate";
import { addDept, updateDept, getDept } from "@/api/system/dept";
export default {
  props: {
    did:{
      type:Number,
      default:()=>null
    }
  },
  name: "addEnterprise",
  data() {
    return {
      cateArr: [],
      // 表单参数
      form: {
        cateArr:[],
        parentId: 1000002,
        deptName: undefined, //名称
        leader: undefined, //负责人
        phone: undefined, //电话
        status: 0, //状态（0正常 1停用）
        license: undefined, //营业执照照片
        code: undefined, //统一社会信用代码
        food: undefined, //食品经营许可证
        idCardTop: undefined, //法人身份证正面
        idCardBack: undefined, //法人身份证反面
        foodInspector: undefined, //食品检测员（高级）
        health: undefined, //经营人员健康证
        performance: undefined, //业绩证明
        cate: undefined, //所属类目
        nature: undefined, //公司性质
        aptitude: undefined, //纳税人资质
        area: undefined, //面积
        equity: undefined, //产权
        equityCert: undefined, //不动产权证+租房合同
        iso9001: undefined, //iso9001
        iso14001: undefined, //iso14001
        haccp: undefined, //haccp
        cnas: undefined, //cnas
        car: undefined, //车辆
        carNum1: undefined, //常温车数量
        carNum2: undefined, //冷藏车数量
        isCar: 0, //是否具备运输系统
        foodInsurance: undefined, //食品保险
        sumInsured: undefined, //保额
        socialSecurity: undefined, //纳税证明，社保
        notOpen: undefined, //not_open
        lianOpen: undefined, //lian_open
        open: undefined, //open
        type: undefined, //type
        address: undefined, //经营场地
        email: undefined, //邮箱
        other: undefined, //其他资质
        type: 0,
      },
      // 表单校验
      rules: {
        deptName: [
          { required: true, message: "请输入企业名称", trigger: "blur" },
        ],
        code: [{ required: true, message: "请输入信用代码", trigger: "blur" }],
        cateArr: [
          {
            required: true,
            message: "请选择类目",
            trigger: ["blur", "change"],
          },
        ],
        nature: [
          { required: true, message: "请输入公司性质", trigger: "blur" },
        ],
        aptitude: [
          { required: true, message: "请输入纳税人资质", trigger: "blur" },
        ],
        leader: [
          { required: true, message: "请输入负责人姓名", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "请输入负责人电话", trigger: "blur" },
        ],

        license: [
          {
            required: true,
            message: "请上传营业执照照片",
            trigger: ["blur", "change"],
          },
        ],

        food: [
          {
            required: true,
            message: "请上传食品经营许可证照片",
            trigger: ["blur", "change"],
          },
        ],
        idCardTop: [
          {
            required: true,
            message: "请上传法人身份证正面",
            trigger: ["blur", "change"],
          },
        ],
        idCardBack: [
          {
            required: true,
            message: "请上传法人身份证反面",
            trigger: ["blur", "change"],
          },
        ],

        foodInspector: [
          {
            required: true,
            message: "请上传食品检测员（高级）",
            trigger: ["blur", "change"],
          },
        ],
        health: [
          {
            required: true,
            message: "请上传经营人员健康证",
            trigger: ["blur", "change"],
          },
        ],
        performance: [
          {
            required: true,
            message: "请上传业绩证明",
            trigger: ["blur", "change"],
          },
        ],
        equityCert: [
          {
            required: true,
            message: "请上传产权证明",
            trigger: ["blur", "change"],
          },
        ],
        car: [
          {
            required: true,
            message: "请上传车辆照片",
            trigger: ["blur", "change"],
          },
        ],
        carNum1: [
          {
            required: true,
            message: "请上传常温车照片",
            trigger: ["blur", "change"],
          },
        ],
        carNum2: [
          {
            required: true,
            message: "请上传常温车照片",
            trigger: ["blur", "change"],
          },
        ],
        foodInsurance: [
          {
            required: true,
            message: "请上传食品保险照片",
            trigger: ["blur", "change"],
          },
        ],
        sumInsured: [
          {
            required: true,
            message: "请输入保额照",
            trigger: ["blur", "change"],
          },
        ],
        iso9001: [
          {
            required: true,
            message: "请上传国家企业信用信息公示系统查询结果截图",
            trigger: ["blur", "change"],
          },
        ],
        socialSecurity: [
          {
            required: true,
            message: "请上传纳税证明.社保照片",
            trigger: ["blur", "change"],
          },
        ],
        // email: [
        //   {
        //     type: "email",
        //     message: "请输入正确的邮箱地址",
        //     trigger: ["blur", "change"],
        //   },
        // ],
        // phone: [
        //   {
        //     pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        //     message: "请输入正确的手机号码",
        //     trigger: "blur",
        //   },
        // ],
      },
    };
  },
  created() {
    this.show();
  },
  methods: {
    chaSel(e){
      // console.log(e)
      this.$forceUpdate()
    },
    show() {
      getFormatCateData({ pageNum: -1, pagePage: -1 }).then((response) => {
        this.cateArr = response.rows;
      });

      console.log('pppp')
      console.log(this.did)
      if (this.did != null) {
        console.log('pppp')
        getDept(this.did).then((response) => {
          this.form = response.data;
          this.form.cateArr = this.form.cate.split(',')
          console.log(this.form.cateArr)
        });
      }
    },
    cancel() {
      this.$emit("cancel");
    },
    /** 提交按钮 */
    submitForm: function () {
      console.log(this.form);
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.cate = this.form.cateArr.toString();
          if (this.form.deptId != undefined) {
            updateDept(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.$emit("submitForm");
            });
          } else {
            addDept(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.$emit("submitForm");
              // this.open = false;
              // this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
  